{% extends 'app01/admin/home.html' %}
{% block content %}


    <div class="panel panel-default">
        <div class="panel-heading">管理员的文件</div>
        <div class="panel-body">
            <div class="container">
                <div class="row">

                    <div class="col-md-10">
                        <table class="table table-hover table-striped">
                            <thead>
                            <tr>
                                <th>文件名</th>
                                <th>文件保存名字</th>
                                <th>已导入</th>
                                <th>操作</th>
                                <th>操作</th>

                            </tr>
                            </thead>
                            <tbady>
                                {% for file in files %}
                                    <tr>
                                        <td>{{ file.name }}</td>
                                        <td>{{ file.filename }}</td>
                                        <td>{{ file.status }}</td>
                                        <td><a class="btn btn-success btn-sm" target="_blank" href="/media/admin_file/{{ file.filename }}">预览</a>
                                            <a class="btn btn-danger btn-sm del_btn" del_id="{{ file.id }}">删除</a>
                                        </td>
                                        <td>
                                            <a  class="btn btn-primary btn-sm add_user"
                                               href="/app01/admin/add/users?filename={{ file.filename }}&status={{ file.status }}&id={{file.id }}" target="_blank">批量导入用户</a>
{#                                            <a href="#"  class="btn btn-primary btn-sm add_user" filename="{{ file.filename }}" file_id="{{file.id }}" status="{{ file.status  }}">批量导入用户</a>#}
                                        </td>
                                    </tr>

                                {% endfor %}

                            </tbady>
                        </table>

                        {# 分页显示 #}
                        <div class="pager">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    {{ page_html }}
                                </ul>
                            </nav>
                        </div>

                    </div>

                </div>

            </div>


        </div>
    </div>




{% endblock %}
{#文件预览的模态框开始#}


{#文件预览的模态框结束#}

{% block js %}
    <script>
       //删除文件的确认
        $('.del_btn').click(function () {
            //删除的二次确认
            let op = confirm('确认删除吗？')
            let del_id = $(this).attr('del_id')
            $.ajax({
                url: '',
                type: 'post',
                data: {'del_id': del_id, 'op': op},
                success: function (array) {
                    if (array.code === 100) {
                        alert(array.msg)
                        window.location.reload()
                    } else if (array.code === 200 && op === true) {
                        alert(array.msg)
                    }

                }
            })
        });

    //鼠标获取焦点时，错误信息不显示了。
        $('#id_confirm_pwd').focus(function () {
            $('#error').text('')

        })


    //修改密码的ajax请求

    $('#id_editer').click(function () {

        let old_pwd = $('#id_old_pwd').val()
        let new_pwd = $('#id_new_pwd').val()
        let comfir_pwd = $('#id_confirm_pwd').val()

        $.ajax({
            url:'/app01/set_password/',
            type: 'post',
            data:{'old_pwd':old_pwd,'new_pwd':new_pwd,'confirm_pwd':comfir_pwd},
            success:function (attr) {
                if(attr.code===1000){
                    alert(attr.msg)
                    window.location.reload()
                } else if(attr.code===2000){
                    $('#error').text(attr.msg)
                }else  if(attr.code===3000){
                    $('#error').text(attr.msg)
                }
            }
        })


    })

    </script>
{% endblock %}